<template>
	<view class="list-wp">
		<!-- 列表信息 -->
		<view class="list" v-if="list && list.length>0">
			<view class="item" hover-class="hover-class" v-for="(item,index) in list" :key="index"
				@click="toDetail(item)">
				<view class="title u-line-1">
					{{item.title?item.title:''}}
				</view>
				<view class="icon-wp">
					<u-icon name="arrow-right" color="#E5E6EB" size="30rpx"></u-icon>
				</view>
			</view>
		</view>
		<view class="no-data" v-else>
			<img src="https://file.casugn.com/storecompcard/temp/空页面@2x_1683700615237.png" alt="">
			<view class="no-data-text">
				暂无数据
			</view>
		</view>
		<bottom-button @handleClick="goToFeedback" title="问题反馈"></bottom-button>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	import bottomButton from '@/components/bottom-button/bottom-button.vue'
	export default {
		data() {
			return {
				list: [],
				pageNo: 1,
				pageSize: 15,
				total: 0
			};
		},
		components: {
			bottomButton
		},
		onReachBottom() {
			if (this.pageNo * this.pageSize < this.total) {
				this.pageNo++
				this.getList()
			}
		},
		onLoad() {
			this.getList('reset')
		},
		onShow() {

		},
		onPullDownRefresh() {
			this.getList('reset')
		},
		computed: {
			...mapGetters(['userInfo']),
		},
		methods: {
			async getList(type) {
				uni.showLoading({

				})
				if (type == 'reset') {
					this.pageNo = 1
					this.total = 0
					this.list = []
				}
				let payload = {
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					openId: this.userInfo.openId
				}
				let res = await this.$api.getHelpList(payload)
				if (res.success && res.result.records) {
					if (type == 'reset') {
						this.list = res.result.records
					} else {
						this.list = [...this.list, ...res.result.records]
					}
					this.total = res.result.total
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				}
				uni.hideLoading()
				uni.stopPullDownRefresh()
			},
			goToFeedback() {
				if (!this.userInfo.id) {
					return this.$showToast('请先创建名片')
				}
				uni.navigateTo({
					url: '/pagesBusiness/feedback/feedback'
				})
			},
			toDetail({
				id,
				helpType,
				content
			}) {
				if (helpType == 0) {
					uni.navigateTo({
						url: '/pagesBusiness/helpList/helpListDetail?id=' + id
					})
				} else if (helpType == 1) {
					uni.navigateTo({
						url: '/pagesBusiness/helpList/helpListVideoDetail?id=' + id
					})
				} else if (helpType == 2) {
					uni.navigateTo({
						url: '/pagesBusiness/helpList/helpListVideoDetail?url=' + content
					})
				} else {
					uni.showToast({
						title: '暂无详情',
						icon: 'none'
					})
				}

			}
		}
	}
</script>

<style lang="scss" scoped>
	.hover-class {
		background-color: #f7f8fa;
	}

	.list-wp {
		position: absolute;
		width: 100%;
		min-height: 100%;
		padding-bottom: calc(180rpx + constant(safe-area-inset-bottom));
		padding-bottom: calc(180rpx + env(safe-area-inset-bottom));
		box-sizing: border-box;

		.list {
			min-height: 100%;
			overflow: auto;

			.item {
				margin: 0 30rpx;
				border-bottom: 1rpx solid #E5E6EB;
				height: 110rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.title {
					margin-left: 20rpx;
					flex: 1;
					font-size: 28rpx;
				}
			}
		}

		.no-data {
			height: 296rpx;
			margin: 0 auto;
			margin-top: 240rpx;
			text-align: center;

			img {
				width: 240rpx;
				height: 240rpx;
			}

			.no-data-text {
				font-size: 28rpx;
				font-weight: 400;
				color: #86909C;
				line-height: 39rpx;
				margin-top: 16rpx;
			}

		}

	}
</style>